/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package coneccion;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author JONATHAN
 */
public class ConnectOra {

    private String driver, url, ip, bd, usr, pass;
    private Connection conexion;
    private String Mensaje = "..";
    private String url_Servidor;

    public ConnectOra(String ip, String bd, String usr, String pass) {
        driver = "oracle.jdbc.driver.OracleDriver";

        this.bd = bd;
        this.usr = usr;
        this.pass = pass;

        //url_Servidor = "jdbc:oracle:thin:" + usr + "/" + pass + "@" + ip + ":" + 1521 + ":" + bd;
        url = "jdbc:oracle:thin:@" + ip + ":1521:" + bd;

        try {
            Class.forName(driver).newInstance();


            DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
            conexion = DriverManager.getConnection(url, usr, pass);

            // revisan el log para ver que tira....
            setMensaje("Conexion a Base de Datos " + bd + " Exitosa");

        } catch (Exception exc) {
            setMensaje("Error al tratar de abrir la base de Datos " + bd
                    + " : " + exc.getCause());
        }
    }

    private void setMensaje(String string) {
        Mensaje = string;
    }

    public String getMensaje() {
        return this.Mensaje;
    }

    public boolean ejecutaConsultaUsuario(String cod_usuario, String contrasena) {
        boolean indicador = false;
        try {
            String sql="SELECT * FROM TRON2000.USUARIOS WHERE USUARIO="+"'"+cod_usuario+"'"+" AND CONTRASENA="+"'"+contrasena+"'"+"";
            java.sql.Statement st =conexion.createStatement();
            ResultSet rs=st.executeQuery(sql);
            while(rs.next()){
                indicador=true;
            }
        } catch (SQLException ex) {
            indicador=false;
            System.out.println("--------- "+ex.getCause()+" -- "+ex.getMessage());
        }
        return indicador;
    }
}
